<!DOCTYPE html>
<html>
<head>
    <title>记账本</title>
    <link rel='stylesheet' href='/stylesheets/style.css' />
    <style>
        .container {
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        .record-item {
            background-color: #f9f9f9;
            border: 1px solid #ddd;
            border-radius: 8px;
            padding: 15px;
            margin-bottom: 15px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .record-item.income {
            background-color: #d4edda;
            border-color: #c3e6cb;
        }
        .record-item.expense {
            background-color: #f8d7da;
            border-color: #f5c6cb;
        }
        .record-date {
            font-size: 12px;
            color: #666;
            margin-bottom: 5px;
        }
        .record-title {
            font-size: 16px;
            font-weight: bold;
            margin-bottom: 5px;
        }
        .record-type {
            display: inline-block;
            padding: 2px 8px;
            border-radius: 12px;
            font-size: 12px;
            color: white;
        }
        .record-type.income {
            background-color: #28a745;
        }
        .record-type.expense {
            background-color: #ffc107;
            color: #212529;
        }
        .record-amount {
            font-size: 18px;
            font-weight: bold;
        }
        .delete-btn {
            background: none;
            border: none;
            font-size: 18px;
            cursor: pointer;
            color: #666;
        }
        .delete-btn:hover {
            color: #dc3545;
        }
        .add-btn {
            position: fixed;
            bottom: 30px;
            right: 100px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 50%;
            width: 60px;
            height: 60px;
            font-size: 24px;
            cursor: pointer;
            box-shadow: 0 2px 10px rgba(0,0,0,0.2);
        }
        .add-btn:hover {
            background-color: #0056b3;
        }
        .logout-btn {
            position: fixed;
            bottom: 30px;
            right: 30px;
            background-color: #dc3545;
            color: white;
            border: none;
            border-radius: 50%;
            width: 60px;
            height: 60px;
            font-size: 16px;
            cursor: pointer;
            box-shadow: 0 2px 10px rgba(0,0,0,0.2);
        }
        .logout-btn:hover {
            background-color: #c82333;
        }
    </style>
</head>
<body>
    <div class="container">
        <h2><%= title %></h2>
        <!-- 可以通过模板引擎动态渲染更多记录 -->
        <% if (typeof records !== 'undefined' && records.length > 0) { %>
            <% records.forEach(function(record) { %>
                <div title="<%= record.remarks %>" class="record-item <%= record.type === 1 ? 'income' : 'expense' %>">
                    <div>
                        <div class="record-date"><%= moment(record.time).format('YYYY-MM-DD') %></div>
                        <div class="record-title"><%= record.title %></div>
                        <span class="record-type <%= record.type === 1 ? 'income' : 'expense' %>"><%= record.type === 1 ? '收入' : '支出' %></span>
                    </div>
                    <div style="display: flex; align-items: center; gap: 15px;">
                        <div class="record-amount"><%= record.account %> 元</div>
                        <a class="delete-btn" href="/account/<%= record._id %>">×</a>
                    </div>
                </div>
            <% }); %>
        <% } %>
    </div>
    
    <button class="add-btn" onclick="location.href='/account/add'">+</button>
    <!-- 添加退出按钮 -->
    <form action="/logout" method="post">
        <button class="logout-btn" type="submit">退出</button>
    </form>

</body>
<script>
    const deleteBtn = document.querySelectorAll('.delete-btn');

    deleteBtn.forEach(item => {
        item.addEventListener('click', (e) => {
            if (confirm('确定删除吗？')) {
                return true
            } else {
                e.preventDefault();
            }
        })
    })

    console.log('deleteBtn', deleteBtn);

    
</script>
</html>